#ifndef IMAGEWIDGET_H
#define IMAGEWIDGET_H

#include <QWidget>
#include <QVBoxLayout>
#include <QHBoxLayout>
#include <QPushButton>
#include <QCheckBox>
#include <QSpacerItem>
#include "touchbutton.h"
#include "transparentlistview.h"
#include "models/imagemodel.h"

#include <QStyledItemDelegate>
#include <QPixmap>

class ImageItemDelegate : public QStyledItemDelegate
{
    Q_OBJECT
public:
    explicit ImageItemDelegate(QObject* parent = nullptr);
    void paint(QPainter* painter, const QStyleOptionViewItem& option,
               const QModelIndex& index) const override;
private:
    QPixmap m_checkedPixmap;
    QPixmap m_uncheckedPixmap;
};




class ImageWidget : public QWidget
{
    Q_OBJECT
public:
    explicit ImageWidget(QWidget *parent = nullptr);
    bool isSelectMode();
protected:
    void mousePressEvent(QMouseEvent* event) override;
    void mouseMoveEvent(QMouseEvent* event) override;
    void mouseReleaseEvent(QMouseEvent* event) override;
    void resizeEvent(QResizeEvent* event) override;
    void setVisible(bool visible) override;
    void initUI();
    void updateSelectAllCheckBoxState();
private slots:
    void onSelectButtonClicked();
    void onDeleteButtonClicked();
    void onCancelButtonClicked();
    void onSelectAllClicked();

private:
    TransparentListView* m_imageListView;
    TouchButton* m_selectButton;
    TouchButton* m_deleteButton;
    TouchButton* m_cancelButton;
    QCheckBox* m_selectAllCheckBox;
    bool m_isSelectMode;
    QRubberBand* m_rubberBand;
    QPoint m_rubberBandOrigin;
    bool m_initialClickState;
    bool m_initialStateSet;
    int m_initialScrollOffset;
    QMap<int, bool> m_itemOriginalStates;
    QPoint m_pressPos;         // 记录鼠标按下位置
    bool m_hasMoved = false;   // 标记鼠标是否移动
    QVBoxLayout * m_listLayout = NULL;
};

#endif // IMAGEWIDGET_H
